package cn.com.scooper.aop.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class AlarmGradeValidator implements ConstraintValidator<ValidAlarmGrade, String> {
    private static final String[] ALLOWED_VALUES = {"E3801", "E3802", "E3803"};

    @Override
    public void initialize(ValidAlarmGrade constraintAnnotation) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }

        for (String allowedValue : ALLOWED_VALUES) {
            if (allowedValue.equals(value)) {
                return true;
            }
        }

        return false;
    }
}
